package com.easylinkin.linkappapi.alarm.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.alarm.entity.AlarmProcess;
import com.easylinkin.linkappapi.alarm.service.AlarmProcessService;
import com.easylinkin.linkappapi.annotation.CommonOperateLogAnnotate;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.operatelog.constant.LogConstant.LogModule;
import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author TongJie
 * @since 2020-04-27
 */
@RestController
@Api(value="告警处理",tags={"告警处理"})
@RequestMapping("/alarm/alarmProcess")
public class AlarmProcessController {

    @Resource
    AlarmProcessService service;

    @ApiOperation("新增告警处理")
    @PostMapping("add")
    @CommonOperateLogAnnotate(module = LogModule.ALARM_PROCESS, desc = "新增告警处理")
    public RestMessage add(@RequestBody @Valid AlarmProcess alarmProcess) {
        service.add(alarmProcess);
        return RestBuilders.successBuilder().build();
    }

    @ApiOperation("批量新增告警处理")
    @PostMapping("addBatch")
    @CommonOperateLogAnnotate(module = LogModule.ALARM_PROCESS, desc = "批量新增告警处理")
    public RestMessage addBatch(@RequestParam("processResult") String processResult, @RequestParam("mistakeFlag") Integer mistakeFlag, @RequestBody List<AlarmProcess> alarmProcessList) {
        service.addBatch(processResult,mistakeFlag,alarmProcessList);
        return RestBuilders.successBuilder().build();
    }

    /**
     * 2021-11-11：未开发完成（空接口）
     * @param alarmProcess
     * @return
     */
    @ApiOperation("获取告警处理详情")
    @PostMapping("get")
    public RestMessage getAlarmProcess(@RequestBody AlarmProcess alarmProcess) {
        Assert.notNull(alarmProcess, "alarmProcess 不能为空");
        return RestBuilders.successBuilder().data(service.getAlarmProcesses(alarmProcess)).build();
    }

    /**
     * 2021-11-11：未开发完成（空接口）
     * @param requestModel
     * @return
     */
    @ApiOperation("获取告警处理分页数据")
    @PostMapping("getPage")
    public RestMessage getAlarmProcessPage(@RequestBody RequestModel<AlarmProcess> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<AlarmProcess> record = service.getAlarmProcessPage(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder().data(record).build();
    }

    @ApiOperation("根据告警ID获取告警处理详情")
    @PostMapping("getByAlarmId")
    public RestMessage getByAlarmId(@RequestParam("alarmId") String alarmId) {
        Assert.hasLength(alarmId, "alarmId 不能为空");
        return RestBuilders.successBuilder().data(service.getAlarmProcess(alarmId)).build();
    }

    /**
     *  2021-11-11：未开发完成（空接口）
     * @param alarmProcessList
     * @return
     */
    @ApiOperation("批量删除告警处理")
    @PostMapping("deleteBatch")
    @CommonOperateLogAnnotate(module = LogModule.ALARM_PROCESS, desc = "批量删除告警处理")
    public RestMessage deleteBatch(@RequestBody List<AlarmProcess> alarmProcessList) {
        Assert.notEmpty(alarmProcessList, "参数为空");
        return RestBuilders.successBuilder(service.deleteBatch(alarmProcessList)).build();
    }

}
